import java.util.HashMap;
import java.util.Map;

public class CourseSelectionSystem {
    private Map<String, Course> courses = new HashMap<>();
    private Map<String, Teacher> teachers = new HashMap<>();
    private Map<String, Student> students = new HashMap<>();

    // 添加课程
    public void addCourse(Course course) {
        courses.put(course.getCourseId(), course);
    }

    // 添加教师
    public void addTeacher(Teacher teacher) {
        teachers.put(teacher.getTeacherId(), teacher);
    }

    // 添加学生
    public void addStudent(Student student) {
        students.put(student.getStudentId(), student);
    }

    // 教师开课（实际是关联教师和课程）
    public void teacherOpenCourse(String teacherId, String courseId) {
        Teacher teacher = teachers.get(teacherId);
        Course course = courses.get(courseId);
        if (teacher != null && course != null) {
            teacher.setCourseId(courseId);
            course.setTeacherId(teacherId);
            System.out.println(teacher.getTeacherName() + " 成功开设课程：" + course.getCourseName());
        } else {
            System.out.println("教师或课程不存在，开课失败");
        }
    }

    // 打印学生课表
    public void printStudentCourseSchedule(String studentId) {
        Student student = students.get(studentId);
        if (student != null) {
            System.out.println(student.getStudentName() + " 的课表：");
            for (String courseId : student.getCourseIds()) {
                Course course = courses.get(courseId);
                if (course != null) {
                    Teacher teacher = teachers.get(course.getTeacherId());
                    System.out.println("编号：" + course.getCourseId() + "，课程名称：" + course.getCourseName() +
                            "，上课地点：" + course.getLocation() + "，时间：" + course.getTime() +
                            "，授课教师：" + (teacher != null ? teacher.getTeacherName() : "未知"));
                }
            }
        } else {
            System.out.println("学生不存在");
        }
    }
}